package com.bdqn.servlet.admin;

import com.bdqn.entity.ResultInfo;
import com.bdqn.service.CheckWorkService;
import com.bdqn.service.Impl.CheckWorkServiceImpl;
import com.bdqn.util.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/add")
public class AddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String empId = request.getParameter("empId");
        String name = request.getParameter("name");
        String depId = request.getParameter("depId");
        String password = request.getParameter("password");
        CheckWorkService service = new CheckWorkServiceImpl();
        boolean flag =service.addEmp(empId,name,depId,password);
        ResultInfo info = new ResultInfo();
        if(flag){
            info.setFlag(flag);
        }else{
            info.setFlag(flag);
            info.setErrorMsg("工号已存在！");
        }
        JSON.writeAsString(info,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
